def is_prime(number):
  if number <= 1:
    return False
  for i in range(2, int(number**0.5) + 1):
    if number % i == 0:
      return False
  return True

def get_max_prime(input_number):
  if not 1000 <= input_number <= 9999:
    return 0
  digits = list(str(input_number))
  max_prime = 0
  for i in range(len(digits) - 1, -1, -1):
    for j in range(i, -1, -1):
      number = int("".join(digits[j:i+1]))
      if is_prime(number) and number > max_prime:
        max_prime = number
  return max_prime

input_number = int(input("Введите четырёхзначное натуральное число: "))
result = get_max_prime(input_number)
print(result)